package 贪心;

/**
 * @ClassName _376摆动序列
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/12/8 19:51
 * Version 1.0
 **/
public class _376摆动序列 {
    public static void main(String[] args) {
        int a[] = new int[]{3,3,3,2,5};
        int i = wiggleMaxLength(a);
    }
    public static int wiggleMaxLength(int[] nums) {
        if(nums.length < 1){
            return nums.length;
        }
        int curr=0, pre=0;
        int result = 1;
        for(int i = 0; i < nums.length - 1; i++){
            curr = nums[i + 1] - nums[i];
            if((curr > 0 && pre <= 0) || (curr < 0 && pre >= 0)){
                pre = curr;
                result++;
            }
        }
        return result;
    }
}
